package com.hzbank.swancs.weex.module;

import static com.hzbank.swancs.utils.SharedPreferencesUtil.SPKey.CALL_WHITE;
import static com.hzbank.swancs.utils.SharedPreferencesUtil.SPKey.CUSTOM_CYCLE_NO;
import static com.hzbank.swancs.utils.SharedPreferencesUtil.SPKey.IS_DEVICE_BINDING;
import static com.hzbank.swancs.view.menu.bean.SwancsSystemTipsBean.CommonMenu;

import android.content.Context;
import android.graphics.Color;
import android.net.Uri;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.dynamic.DynamicSdk;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.emas.weex.EmasWeex;
import com.emas.weex.bundle.WeexPageFragment;
import com.hzbank.swancs.fragment.remote.viewmodel.OkHttpClient;
import com.hzbank.swancs.help.ClickProxy;
import com.hzbank.swancs.mtop.WeexRequestBean;
import com.hzbank.swancs.utils.DeviceInfoUtil;
import com.hzbank.swancs.utils.FileUtils;
import com.hzbank.swancs.utils.ReflectUtils;
import com.hzbank.swancs.utils.ReflectionApplication;
import com.hzbank.swancs.utils.SharedPreferencesUtil;
import com.hzbank.swancs.utils.ThreadUtils;
import com.hzbank.swancs.utils.ToastUtils;
import com.hzbank.swancs.GlobalConstant;
import com.hzbank.swancs.R;
import com.hzbank.swancs.utils.HLogger;
import com.hzbank.swancs.utils.WriteLogUtil;
import com.hzbank.swancs.view.HCommonDialog;
import com.hzbank.swancs.view.head.SwancsHeadNetUtils;
import com.hzbank.swancs.view.head.WxSwancsHeadView;
import com.hzbank.swancs.view.menu.SwancsSystemMenuManager;
import com.hzbank.swancs.view.menu.WxSwancsSystemMenuView;
import com.hzbank.swancs.view.menu.bean.SwancsMenuRemoveTip;
import com.hzbank.swancs.view.menu.bean.SwancsSystemBean;
import com.hzbank.swancs.view.menu.bean.SwancsSystemTipsBean;
import com.hzbank.swancs.view.menu.bean.TipsInUrlBean;
import com.hzbank.swancs.weex.HWxProgressBar;
import com.hzbank.swancs.weex.WeexFragment;
import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.WXSDKManager;
import com.taobao.weex.annotation.JSMethod;
import com.taobao.weex.ui.action.BasicComponentData;
import com.taobao.weex.ui.component.WXComponent;
import com.taobao.weex.ui.component.WXVContainer;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;


public class MenuModuleView extends WXComponent<FrameLayout> {
    private TreeMap<String, Fragment> hashMap;
    private FragmentManager mSupportFragmentManager;

    public static String mInstanceId;
    public static String mRef;

    private FrameLayout rootView;
    private LinearLayout menuTipsL;

    private Handler mHandler;
    private SwancsSystemBean closedSwancsSystem;

    private HCommonDialog hDialog;

    private static List<SwancsSystemTipsBean> menuTips = new LinkedList<>();

    private WxSwancsSystemMenuView swancsSystemMenuView;

    private PageRemovedCallback pageRemovedCallback; //界面删除完成回调，删除页面时发firevent需要延时操作。

    private PageSwitchedCallback pageSwitchedCallback;//界面切换完成回调，切换和删除顺序问题

    private String[] urlInRemoveTip; //保存删除菜单标签内部的url集合

    public MenuModuleView(WXSDKInstance instance, WXVContainer parent, BasicComponentData basicComponentData) {
        super(instance, parent, basicComponentData);

        mInstanceId = instance.getInstanceId();
        mRef = basicComponentData.mRef;
    }

    public MenuModuleView(WXSDKInstance instance, WXVContainer parent, int type, BasicComponentData basicComponentData) {
        super(instance, parent, type, basicComponentData);

        mInstanceId = instance.getInstanceId();
        mRef = basicComponentData.mRef;
    }

    @Override
    protected FrameLayout initComponentHostView(@NonNull Context context) {
        init();
        rootView = (FrameLayout) LayoutInflater.from(context).inflate(R.layout.view_module_menu, null);

        if(null == rootView) return null;
        menuTipsL = rootView.findViewById(R.id.menuTipsL);

        rootView.post(() -> {

            //请求设备是否绑定叫号机

            try{

                HashMap params = new HashMap();
                params.put("deviceId", DeviceInfoUtil.getAndroidId(getContext()));

                WeexRequestBean weexRequestBean = new WeexRequestBean();
                weexRequestBean.setApiName("emas.swan.trans.selectOne");
                weexRequestBean.setRequestMethod("POST");
                weexRequestBean.setVersion("1.0");

                new SwancsHeadNetUtils.NetBuilder().setIsJsonParam(false).setGetWayParams(weexRequestBean).setParams(params).setCommonParams(null).setNetCallback(new OkHttpClient.OkCallCancelBack() {
                    @Override
                    public void fail(JSONObject error) {
                        //ignore
                        HLogger.logWithTag("MenuModuleView", "设备是否绑定叫号机请求失败="+((null == error) ? "内容为空" : JSON.toJSONString(error)));
                    }

                    @Override
                    public void success(JSONObject data) {

                        HLogger.logWithTag("MenuModuleView", "设备是否绑定叫号机="+((null == data) ? "内容为空" : JSON.toJSONString(data)));

                        if(null!=data){
                            
                            JSONObject transDeviceInfo = data.getJSONObject("transDeviceInfo");
                            
                            if(null != transDeviceInfo){

                                String deviceStatus = transDeviceInfo.getString("deviceStatus");

                                //2-未绑定
                                //1-绑定
                                if(null!=deviceStatus && TextUtils.equals("1", deviceStatus)){

                                    SharedPreferencesUtil.getInstance().put(ReflectionApplication.getApplication(), IS_DEVICE_BINDING, true);
                                }else {
                                    SharedPreferencesUtil.getInstance().put(ReflectionApplication.getApplication(), IS_DEVICE_BINDING, false);
                                }
                            }
                        }

                    }
                }).build().doRequest();


            }catch (Exception e){
                //ignore
            }

        });
        return rootView;
    }

    public void init() {
        FragmentActivity activity = (FragmentActivity) getContext();
        mSupportFragmentManager = activity.getSupportFragmentManager();
        hashMap = new TreeMap<>();
    }

    public void showMenu(SwancsSystemBean swancsSystem, boolean shouldCheck, String localUrl){

        if(null == swancsSystem || TextUtils.isEmpty(swancsSystem.menuUrl)){

            return;
        }

        String url = null;
        if(isLocal() && !TextUtils.isEmpty(localUrl)){

            url = localUrl;
        } else {

            url = assembly(swancsSystem);
        }

        //展示tips标签
        if(showMenuTips(swancsSystem, url, shouldCheck)){

            WriteLogUtil.getInstance().saveLoaclSystemMenuLog("showMenu[ssb,b,s = " + url + "\n");

            //跳转url，打开fragment
            showMenu(url);
        };

    }

    private String assembly(SwancsSystemBean swancsSystem){

        if(null== swancsSystem) return null;

        String url = null;

        if(isLocal()){

            url = GlobalConstant.pageUrlBase.substring(0, GlobalConstant.pageUrlBase.indexOf("pages/") + 6)
                    + swancsSystem.menuUrl
                    + GlobalConstant.pageUrlBase.substring(GlobalConstant.pageUrlBase.indexOf("/entry.js"))
                    + "&menuCode="
                    + swancsSystem.menuCode;

            HLogger.logWithTag("MenuModuleView", "本地路径1="+url);

        } else {

            //封装跳转url
            url = GlobalConstant.pageUrlPrefix
                    + swancsSystem.module
                    + "/pages/"
                    + swancsSystem.menuUrl
                    + GlobalConstant.pageUrlSuffix
                    + swancsSystem.menuCode;

        }

        return url;
    }

    private String assembly(SwancsSystemBean swancsSystem,  String params){

        if(null== swancsSystem || TextUtils.isEmpty(params)) return null;

        String url = null;

        if(isLocal()){

            url = GlobalConstant.pageUrlBase.substring(0, GlobalConstant.pageUrlBase.indexOf("pages/") + 6)
                    + swancsSystem.menuUrl
                    + GlobalConstant.pageUrlBase.substring(GlobalConstant.pageUrlBase.indexOf("/entry.js"))
                    + "&menuCode="
                    + swancsSystem.menuCode
                    +"&"
                    +params;

            HLogger.logWithTag("MenuModuleView", "本地路径2="+url);

        } else {

            //封装跳转url
            url = GlobalConstant.pageUrlPrefix
                    + swancsSystem.module
                    +"/pages/"
                    + swancsSystem.menuUrl
                    + GlobalConstant.pageUrlSuffix
                    + swancsSystem.menuCode
                    +"&"
                    +params;
        }

        return url;
    }

    private String assembly(SwancsSystemBean swancsSystem,  String customerNo, boolean skipNo){

        if(null== swancsSystem || TextUtils.isEmpty(customerNo)) return null;

        String url = null;

        if(isLocal()){

            url = GlobalConstant.pageUrlBase.substring(0, GlobalConstant.pageUrlBase.indexOf("pages/") + 6)
                    + swancsSystem.menuUrl
                    + GlobalConstant.pageUrlBase.substring(GlobalConstant.pageUrlBase.indexOf("/entry.js"))
                    + "&menuCode="
                    + swancsSystem.menuCode + "&customerNo="+customerNo + "&skipNo="+skipNo;

            HLogger.logWithTag("MenuModuleView", "本地路径3="+url);

        } else {

            //封装跳转url
            url = GlobalConstant.pageUrlPrefix
                    + swancsSystem.module
                    +"/pages/"
                    + swancsSystem.menuUrl
                    + GlobalConstant.pageUrlSuffix
                    + swancsSystem.menuCode + "&customerNo="+customerNo + "&skipNo="+skipNo;

        }

        return url;
    }

    //根据本地传过来的ip判断是否为local
    private boolean isLocal(){

        return GlobalConstant.pageUrlBase.contains("index.html?_wx_tpl");
    }

    private Handler createHandler(){

        if(null!=mHandler){
            mHandler.removeCallbacksAndMessages(null);
            mHandler = null;
        }
        
        mHandler = new Handler();

        return mHandler;
        
    }

    public void showMenuParams(SwancsSystemBean swancsSystem, String params, boolean shouldCheck, String localUrl){

        if(null == swancsSystem || TextUtils.isEmpty(swancsSystem.menuUrl)){

            return;
        }

            //封装跳转url
        String url = null;
        if(isLocal() && !TextUtils.isEmpty(localUrl)){

            url = localUrl;
        } else {

            url = assembly(swancsSystem, params);
        }

        //展示tips标签
        if(showMenuTips(swancsSystem, url, shouldCheck)){

            WriteLogUtil.getInstance().saveLoaclSystemMenuLog("showMenuParams[ssb,s,b,s = " + url + "\n");

            //跳转url，打开fragment
            showMenu(url);
        };

    }

    public void showMenu(SwancsSystemBean swancsSystem, String skipUrl, boolean shouldCheck){

        if(null == swancsSystem || TextUtils.isEmpty(skipUrl)){

            return;
        }

        //展示tips标签
        if(showMenuTips(swancsSystem, skipUrl, shouldCheck)){

            WriteLogUtil.getInstance().saveLoaclSystemMenuLog("showMenu[ssb,s,b = " + skipUrl + "\n");

            //跳转url，打开fragment
            showMenu(skipUrl);
        };

    }

    public void showMenu(SwancsSystemBean swancsSystem, String customerNo, boolean skipNo, boolean shouldCheck){

        if(null == swancsSystem
                || TextUtils.isEmpty(swancsSystem.menuUrl)
                || TextUtils.isEmpty(customerNo)){

            return;
        }

            //封装跳转url
        String url = assembly(swancsSystem, customerNo, skipNo);

        //强制转成common菜单
        swancsSystem.menuCode = CommonMenu;

        //展示tips标签
        if(showMenuTips(swancsSystem, url, shouldCheck)){

            WriteLogUtil.getInstance().saveLoaclSystemMenuLog("showMenu[ssb,s,b,b = " + url + "\n");

            //跳转url，打开fragment
            showMenu(url);
        };
    }

    private boolean showMenuTips(SwancsSystemBean swancsSystem, String menuSkipUrl, boolean shouldCheck){

        if(null == swancsSystem || TextUtils.isEmpty(menuSkipUrl)){
            return false;
        }

        if(null == menuTips){

            menuTips = new LinkedList<>();
        }

        SwancsSystemTipsBean swancsSystemTip = changeMenu(swancsSystem, menuSkipUrl);

        if(null == swancsSystemTip){

            return false;
        }

        return handleTips(swancsSystemTip, shouldCheck, menuSkipUrl);
    }

    private SwancsSystemTipsBean menuExists(SwancsSystemTipsBean swancsSystemTip){

        if(null == swancsSystemTip) return null;

        for(SwancsSystemTipsBean subSystemTip : menuTips){

            if(null!=subSystemTip
                    && subSystemTip.menuTipEquals(swancsSystemTip)){

                    return subSystemTip;
            }
        }

        return null;

    }

    private boolean handleTips(SwancsSystemTipsBean swancsSystemTip, boolean shouldCheck, String skipUrl){

        if(null!=menuTips && null!=swancsSystemTip){

            if(!isCallCycleNo()
                    && TextUtils.equals("C", swancsSystemTip.menuSort)
                    && deviceIsBinding()){

                //必须在对客叫号情况下进行办理
                try{

                    if(null != hDialog){
                        hDialog.cancel();
                        hDialog = null;
                    }

                    hDialog = new HCommonDialog.Builder()
                            .setContext(getContext())
                            .setTitle("确认")
                            .setMessage("必须在对客叫号情况下进行办理")
                            .setCancelable(false)
                            .setCancelIsSure(true)
                            .setDialogCallback(new HCommonDialog.DialogCallback() {
                                @Override
                                public void doSure() {
                                    //ignore
                                }
                            })
                            .build();
                    hDialog.showDialog();
                }catch (Exception e){
                    //ignore
                }

                return false;
            }

            if(menuTips.isEmpty()){
                menuTips.add(swancsSystemTip);

                if(TextUtils.equals(swancsSystemTip.transType, "T")){

                    //主交易 打开时删除影响文件

                    try{

                        deleteCapture();
                    }catch (Exception e){
                        //ignore

                    }

                }

            } else {

                SwancsSystemTipsBean verfyTip = menuExists(swancsSystemTip);

                if(null!= verfyTip){

                    if(!verfyTip.menuTopsStatus){

                        String oldSkipUrl = verfyTip.getShowUrl();

                        if(verfyTip.isSameUrl(skipUrl)){

                            //切换菜单
                            switchMenu(verfyTip);

                        } else {

                            //切换菜单后，加载新url
                            switchAndShowMenu(verfyTip, oldSkipUrl);

                        }
                    }

                    return false;
                }

                String menuTransType = swancsSystemTip.transType;

                if(swancsSystemTip.hasTransType() && hasMoremany(menuTransType) && shouldCheck){

                    showMoreMayMsg(menuTransType);

                    return false;
                }

                if(TextUtils.equals(menuTransType, "T")){

                    //主交易 打开时删除影响文件

                    try{

                        deleteCapture();
                    }catch (Exception e){
                        //ignore

                    }

                }

                //改变tip显示状态
                swancsSystemTip.menuTopsStatus = true;

                for(SwancsSystemTipsBean oldTip : menuTips){

                    if(null!=oldTip){
                        oldTip.menuTopsStatus = false;
                    }
                }

                menuTips.add(swancsSystemTip);
            }

            addTipsView();

            return true;
        }

        return false;
    }

    //加载menu tip view
    private void addTipsView(){

        ThreadUtils.postUI(() -> {

            if(null!=menuTipsL && null!=menuTips && !menuTips.isEmpty()){


                menuTipsL.removeAllViews();

                for(SwancsSystemTipsBean swancsSystemTip : menuTips){

                    if(null!=swancsSystemTip){

                        View itenTipView = LayoutInflater.from(getContext()).inflate(R.layout.view_menu_tip, null);

                        if(null!=itenTipView){

                            TextView menuTipName = itenTipView.findViewById(R.id.menuTipName);
                            ImageView closeMenuIcon = itenTipView.findViewById(R.id.closeMenuIcon);

                            if(swancsSystemTip.menuTopsStatus){

                                //当前显示
                                itenTipView.setBackground(getContext().getResources().getDrawable(R.drawable.drawable_menu_open_bg));
                                menuTipName.setTextColor(Color.parseColor("#333333"));
                                menuTipName.setText(TextUtils.isEmpty(swancsSystemTip.menuName) ?"默认标签" :swancsSystemTip.menuName);
                                closeMenuIcon.setBackground(getContext().getResources().getDrawable(R.drawable.ic_menu_close_black));


                            } else {
                                //当前隐藏
                                itenTipView.setBackground(getContext().getResources().getDrawable(R.color.transparent));
                                menuTipName.setTextColor(Color.parseColor("#ffffff"));
                                menuTipName.setText(TextUtils.isEmpty(swancsSystemTip.menuName) ?"默认标签" :swancsSystemTip.menuName);
                                closeMenuIcon.setBackground(getContext().getResources().getDrawable(R.drawable.ic_menu_close_white));
                            }

                            itenTipView.setTag(R.id.menu_status, swancsSystemTip.menuTopsStatus);
                            itenTipView.setTag(R.id.menu_code, !swancsSystemTip.commonMenu() ? swancsSystemTip.menuCode : swancsSystemTip.getMainUrl());

                            HLogger.logWithTag("SystemMenuCustomer", "添加菜单----菜单码="+((null!=itenTipView) ? String.valueOf(itenTipView.getTag(R.id.menu_code)) : "空"));

                            closeMenuIcon.setOnClickListener(new ClickProxy(v -> {

                                boolean isSuccess = swancsSystemTip.getPageSuccessStatus();
                                //关闭菜单
                                removeMenu(swancsSystemTip, isSuccess, true, null);

                            }));

                            //长按强制删除
                            closeMenuIcon.setOnLongClickListener(new View.OnLongClickListener() {
                                @Override
                                public boolean onLongClick(View v) {

                                    //关闭菜单
                                    removeMenu(swancsSystemTip, false, true, null);
                                    return true;
                                }
                            });

                            itenTipView.setOnClickListener(new ClickProxy(v -> {
                                //切换菜单

                                switchMenu(swancsSystemTip);
                            }));

                            menuTipsL.addView(itenTipView);

                            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) itenTipView.getLayoutParams();
                            lp.width = ViewGroup.LayoutParams.WRAP_CONTENT;
                            lp.height = 40;

                            itenTipView.setLayoutParams(lp);
                        }
                    }


                }

            }

        });
    }

    //提示菜单异常信息
    private void showMoreMayMsg(String menuTransType){

        try {

//            ThreadUtils.postUI(()-> {
//
//                Map<String, Object> params = new TreeMap<>(1<<1);
//                params.put("respCode", "-9999");
//                if(TextUtils.equals(menuTransType, "T")){
//
//                    params.put("respMsg", "主交易最多打开1个");
//                }else if(TextUtils.equals(menuTransType, "A")){
//
//                    params.put("respMsg", "辅交易最多打开3个");
//                }
//                fireEvent("Swancs_Head_Http_Error", params);
//            });

            WxSwancsHeadView swancsHead = ReflectUtils.getComponent(WxSwancsHeadView.mInstanceId, WxSwancsHeadView.mRef);

            if(TextUtils.equals(menuTransType, "T")){

                swancsHead.pushMessageToVue("-9999", "主交易最多打开1个", 1);

                HLogger.logWithTag("MenuModuleView", "主交易最多打开1个");
            } else if(TextUtils.equals(menuTransType, "A")){

                swancsHead.pushMessageToVue("-9999", "辅交易最多打开3个", 1);

                HLogger.logWithTag("MenuModuleView", "辅交易最多打开3个");
            }

        }catch (Exception e){
            e.printStackTrace();
        }
    }

    //判断是否超限
    private boolean hasMoremany(String menuTransType){

        if(TextUtils.equals(menuTransType, "T")){

            //主交易对多一个
            for(SwancsSystemTipsBean menuTip : menuTips){

                if(null != menuTip && TextUtils.equals(menuTip.transType, "T")){

                    return true;
                }
            }


        } else if(TextUtils.equals(menuTransType, "A")){
            //辅交易最多3个
            int aux = 0;

            for(SwancsSystemTipsBean menuTip : menuTips){

                if(null != menuTip && TextUtils.equals(menuTip.transType, "A")){
                    aux ++;

                    if(aux == 3){

                        return true;
                    }
                }
            }

        }

        return false;
    }

    private SwancsSystemTipsBean  changeMenu(SwancsSystemBean swancsSystem, String menuSkipUrl){

        if(null == swancsSystem || TextUtils.isEmpty(menuSkipUrl)) return null;

        SwancsSystemTipsBean swancsSystemTips = new SwancsSystemTipsBean();

        swancsSystemTips.menuName = swancsSystem.menuName;
        if(null== swancsSystemTips.urls) swancsSystemTips.urls = new LinkedList<>();
        TipsInUrlBean tipsInUrl = new TipsInUrlBean(true, menuSkipUrl);
        swancsSystemTips.urls.add(tipsInUrl);
        swancsSystemTips.menuTopsStatus = true;
        swancsSystemTips.transType = swancsSystem.transType;
        swancsSystemTips.menuCode = swancsSystem.menuCode;

        swancsSystemTips.menuSort = swancsSystem.menuSort;

        swancsSystemTips.swancsSystem = swancsSystem;

        return swancsSystemTips;

    }

    private SwancsSystemTipsBean getOpenedMenuTip(String menuUrl){

        if(null == menuTips || menuTips.isEmpty()){
            return null;
        }

        SwancsSystemBean swancsSystem = null;
        if(!TextUtils.isEmpty(menuUrl)){

            swancsSystem = SwancsSystemMenuManager.getDefault().searchMenuByMenuUrl(menuUrl);
        }

        for(SwancsSystemTipsBean swancsSystemTip : menuTips){

            if(null!=swancsSystemTip && null == swancsSystem && swancsSystemTip.menuTopsStatus){

                return swancsSystemTip;
            } else if(null!=swancsSystemTip && null != swancsSystem && TextUtils.equals(swancsSystem.menuCode, swancsSystemTip.menuCode)){
                return swancsSystemTip;
            }
        }

        return null;

    }

    public SwancsSystemTipsBean getOpenedMenuTip(){

        if(null == menuTips || menuTips.isEmpty()){
            return null;
        }

        for(SwancsSystemTipsBean swancsSystemTip : menuTips){

            if(null!=swancsSystemTip && swancsSystemTip.menuTopsStatus){

                return swancsSystemTip;
            }
        }

        return null;

    }

    @JSMethod(uiThread = true)
    public void showMenu(String url) {

        if(TextUtils.isEmpty(url)){

            return;

        }

        WriteLogUtil.getInstance().saveLoaclSystemMenuLog("执行-JSMethod-showMenu" + "\n");

        HLogger.logWithTag("MenuModuleView_New", "showMenu()，url="+url);

        SwancsSystemTipsBean menuTipOpen = getOpenedMenuTip(null);

        if(null == menuTipOpen){
            return;
        }

        HLogger.logWithTag("MenuModuleView", "渲染进程-显示="+Thread.currentThread().getName());

        FragmentTransaction fragmentTransaction = mSupportFragmentManager.beginTransaction();

        if (!hashMap.containsKey(url)) {
            Log.i("MenuModuleView","showMenu页面重新创建");
            hideAllFragment(hashMap);
            Fragment fragment = createFragment(url);

            if(null == fragment){
                return;
            }

            fragmentTransaction.add(R.id.fl_container, fragment);
            hashMap.put(url, fragment);
            menuTipOpen.addShowUrl(url);
        } else {
            Fragment fragment = hashMap.get(url);
            if(null==fragment){
                Log.i("MenuModuleView","showMenu页面缓存失效重新创建");
                //移出后重新创建
                hashMap.remove(url);
                menuTipOpen.removeUrl(url);

                hideAllFragment(hashMap);
                fragment = createFragment(url);
                if(null == fragment){
                    return;
                }

                fragmentTransaction.replace(R.id.fl_container, fragment);
                hashMap.put(url, fragment);
                menuTipOpen.addShowUrl(url);
            } else if(!fragment.isHidden()){
                HLogger.defualtLog("页面当前就显示");
                return;
            } else {
                //复用
                Log.i("MenuModuleView","showMenu页面复用"+url);
                hideAllFragment(hashMap);
                fragmentTransaction.show(fragment);
            }
        }
        fragmentTransaction.commitAllowingStateLoss();
        Log.i("MenuModuleView","showMenu显示菜单==url="+url);

        GlobalConstant.putCustomInfoPage(url);

        return;
    }



    private void hideAllFragment(TreeMap<String, Fragment>map) {
        FragmentTransaction transaction = mSupportFragmentManager.beginTransaction();
        for(Map.Entry<String,Fragment> entry:map.entrySet()){
            Fragment value = entry.getValue();
            transaction.hide(value);
        }
        transaction.commitNowAllowingStateLoss();
    }

    //切换菜单并展示新标签
    public void switchAndShowMenu(SwancsSystemTipsBean swancsSystemTips, String oldSkipUrl){

        if(null == swancsSystemTips || swancsSystemTips.menuTopsStatus || null == menuTips || menuTips.isEmpty()){
            return;
        }

        WriteLogUtil.getInstance().saveLoaclSystemMenuLog("执行switchAndShowMenu" + "\n");

        int position = -1;
        for(int i =0; i < menuTips.size(); i++){

            SwancsSystemTipsBean subTip = menuTips.get(i);

            if(null!=subTip){

                if(subTip.menuTipEquals(swancsSystemTips)){

                    position = i;
                    subTip.menuTopsStatus = true;
                }else {


                    subTip.menuTopsStatus = false;
                }
            }
        }

        if(position > -1){

            //重新渲染菜单标签
            reloadTipView(position);

            HLogger.logWithTag("MenuModuleView", "准备删除url="+oldSkipUrl);

            removeSameMenu(oldSkipUrl, new PageRemovedCallback(){

                @Override
                public void pageRemoved() {

                    if(null!=swancsSystemTips){

                        HLogger.logWithTag("MenuModuleView", "准备打开url="+swancsSystemTips.getShowUrl());

                        showMenu(swancsSystemTips.getShowUrl());
                    }

                    if(null != MenuModuleView.this.pageRemovedCallback){
                        MenuModuleView.this.pageRemovedCallback = null;
                    }


                }
            });

            //切换系统菜单position

            //改成组件获取
            swancsSystemMenuView = getSystemMenuCompontent();
            if(null != swancsSystemMenuView
                    && !swancsSystemTips.commonMenu()) swancsSystemMenuView.searchMenu(swancsSystemTips.menuCode, false);
        }
    }

    public void removeSameMenu(String oldSkipUrl, PageRemovedCallback pageRemovedCallback){

        this.pageRemovedCallback = pageRemovedCallback;
        
        if(TextUtils.isEmpty(oldSkipUrl)){

            if(null!=this.pageRemovedCallback) this.pageRemovedCallback.pageRemoved();

            return;
        }

        removeMenu(-1, oldSkipUrl);
    }

    //切换菜单
    public void switchMenu(SwancsSystemTipsBean swancsSystemTips){

        if(null == swancsSystemTips || swancsSystemTips.menuTopsStatus || null == menuTips || menuTips.isEmpty()){
            return;
        }

        WriteLogUtil.getInstance().saveLoaclSystemMenuLog("执行switchMenu" + "\n");

        int position = -1;
        for(int i =0; i < menuTips.size(); i++){

            SwancsSystemTipsBean subTip = menuTips.get(i);

            if(null!=subTip){

                if(subTip.menuTipEquals(swancsSystemTips)){

                    position = i;
                    subTip.menuTopsStatus = true;
                }else {


                    subTip.menuTopsStatus = false;
                }
            }
        }

        if(position > -1){

            //重新渲染菜单标签
            reloadTipView(position);

            switchMenu(position, swancsSystemTips.getShowUrl());

            //切换系统菜单position

            //改成组件获取
            swancsSystemMenuView = getSystemMenuCompontent();
            if(null != swancsSystemMenuView
                    && !swancsSystemTips.commonMenu()) swancsSystemMenuView.searchMenu(swancsSystemTips.menuCode, false);
        }

    }

    //重新渲染标签视图
    private void reloadTipView(int position){
        //position改成开启，其他的改成关闭
        if(null == menuTipsL || 0 == menuTipsL.getChildCount()){

            return;
        }

        for(int i=0; i< menuTipsL.getChildCount(); i++){

            RelativeLayout childView = (RelativeLayout) menuTipsL.getChildAt(i);

            if(null!=childView){

                if((boolean)(childView.getTag(R.id.menu_status)) && i != position){

                    childView.setTag(R.id.menu_status, false);

                    childView.setBackground(getContext().getResources().getDrawable(R.color.transparent));

                    for(int j =0; j < childView.getChildCount(); j++){

                        View childInnerView = childView.getChildAt(j);
                        if(childInnerView instanceof TextView){
                            ((TextView)childInnerView).setTextColor(Color.parseColor("#ffffff"));
                        } else if(childInnerView instanceof ImageView){

                            ((ImageView)childInnerView).setBackground(getContext().getResources().getDrawable(R.drawable.ic_menu_close_white));
                        }
                    }

                }else if(i == position && !(boolean)(childView.getTag(R.id.menu_status))) {
                    childView.setTag(R.id.menu_status, true);

                    childView.setBackground(getContext().getResources().getDrawable(R.drawable.drawable_menu_open_bg));

                    for(int j =0; j < childView.getChildCount(); j++){

                        View childInnerView = childView.getChildAt(j);
                        if(childInnerView instanceof TextView){
                            ((TextView)childInnerView).setTextColor(Color.parseColor("#333333"));
                        } else if(childInnerView instanceof ImageView){

                            ((ImageView)childInnerView).setBackground(getContext().getResources().getDrawable(R.drawable.ic_menu_close_black));
                        }
                    }
                }
            }

        }


    }

    @JSMethod(uiThread = true)
    public void switchMenu(int index, String url) {

        if(TextUtils.isEmpty(url)){

            return;

        }

        WriteLogUtil.getInstance().saveLoaclSystemMenuLog("执行-JSMethod-switchMenu" + "\n");

        HLogger.logWithTag("MenuModuleView_New", "switchMenu()，url="+url);

        SwancsSystemTipsBean menuTipOpened = getOpenedMenuTip(null);

        if(null == menuTipOpened){
            return;
        }

        HLogger.logWithTag("MenuModuleView", "渲染进程-切换="+Thread.currentThread().getName());

        if(hashMap.containsKey(url)){
            //判断是不是点击显示的菜单，如果是，则不需要重新显示
            FragmentTransaction transaction = mSupportFragmentManager.beginTransaction();
            Fragment fragment = hashMap.get(url);
            if(null == fragment){
                Log.i("switchMenu","显示菜单==url="+url);
                //移出后重新创建
                hashMap.remove(url);
                menuTipOpened.removeUrl(url);
                hideAllFragment(hashMap);
                fragment = createFragment(url);

                if(null == fragment){
                    return;
                }

                transaction.replace(R.id.fl_container, fragment);
                hashMap.put(url, fragment);
                menuTipOpened.addShowUrl(url);
            }
            else if(!fragment.isHidden()){
                Log.i("switchMenu","页面当前就显示"+url);
                return;
            } else {
                hideAllFragment(hashMap);
                transaction.show(fragment);
            }

            transaction.commitAllowingStateLoss();
        }
        Log.i("switchMenu","切换菜单==index="+index+", url="+url);

        GlobalConstant.putCustomInfoPage(url);

        mHandler = createHandler();
        mHandler.postDelayed(() -> {

            if(null!=this.pageSwitchedCallback) this.pageSwitchedCallback.PageSwitchedCallback();
        }, 500);

        return;
    }

    //判断指定的界面是否渲染成功
    private boolean pagerIsRendered(String url){

        if(TextUtils.isEmpty(url)){

            return true;
        }

        Map<String, WXSDKInstance> instances = WXSDKManager.getInstance().getAllInstanceMap();
        if(null == instances || instances.isEmpty()){
            return true;
        }

        Iterator<Map.Entry<String, WXSDKInstance>> iterator = instances.entrySet().iterator();
        if(null!=iterator){

            while (iterator.hasNext()){

                Map.Entry<String, WXSDKInstance> entry = iterator.next();

                if(null!=entry){
                    WXSDKInstance currentWXSDKInstance = entry.getValue();

                    if(null!=currentWXSDKInstance && TextUtils.equals(url, currentWXSDKInstance.getBundleUrl())){
                        return ReflectUtils.getRendered(currentWXSDKInstance );
                    }
                }

            }
        }



        return true;

    }

    public void closeCurrentMenu(){

        //s删除当前展示的菜单

        removeMenu(getOpenedMenuTip(), false, true, null);

    }

    public void removeMenu(SwancsSystemTipsBean swancsSystemTips, boolean shouldSendParams, boolean isManual, PageSwitchedCallback pageSwitchedCallback){

        if(null == swancsSystemTips || null == menuTips || menuTips.isEmpty()) return;
        if(isManual && shouldSendParams) {

            ToastUtils.showShort(getContext(), "目前无法关闭,请继续当前业务");

            return;
        }

        WriteLogUtil.getInstance().saveLoaclSystemMenuLog("执行removeMenu" + "\n");


        int position = -1;
        for(int i =0; i < menuTips.size(); i++){

            SwancsSystemTipsBean subTip = menuTips.get(i);

            if(null!=subTip && subTip.menuTipEquals(swancsSystemTips)){

                position = i;
            }
        }

        if(position > -1){

            SwancsSystemTipsBean preRemoveMenuTip = menuTips.get(position);

            String[] urlInTip = getUrlInTip(preRemoveMenuTip);

            //重新渲染菜单标签
            SwancsMenuRemoveTip removeTip = removeTips(preRemoveMenuTip);

            if(null != removeTip){

//                if(removePage) {
//
//
//                    //removeMenu(position, removeTip.removeUrl);
//                } else {
//
//                    if(null!=removeTip.nextSwancsSystemTip
//                            && !TextUtils.equals(swancsSystemTips.menuCode, removeTip.nextSwancsSystemTip.menuCode)) {
//
//                        int nextMenuPosition = getMenuNewPosition(removeTip.nextSwancsSystemTip);
//
//                        switchMenu(nextMenuPosition, removeTip.nextSwancsSystemTip.getShowUrl());
//                    }
//                }

                removeMenuHandleDelay(position, preRemoveMenuTip, removeTip.removeUrl, urlInTip, isManual, shouldSendParams, true, new PageRemovedCallback() {
                    @Override
                    public void pageRemoved() {

                        if(null!=removeTip.nextSwancsSystemTip
                                && !swancsSystemTips.menuTipEquals(removeTip.nextSwancsSystemTip)) {

                            int nextMenuPosition = getMenuNewPosition(removeTip.nextSwancsSystemTip);

                            MenuModuleView.this.pageSwitchedCallback = pageSwitchedCallback;
                            switchMenu(nextMenuPosition, removeTip.nextSwancsSystemTip.getShowUrl());
                        } else {

                            if(null!=pageSwitchedCallback) pageSwitchedCallback.PageSwitchedCallback();
                        }

                        if(null != MenuModuleView.this.pageRemovedCallback){
                            MenuModuleView.this.pageRemovedCallback = null;
                        }
                    }
                });

                if(null == menuTips || menuTips.isEmpty()){

                    //收缩系统菜单
                    swancsSystemMenuView = getSystemMenuCompontent();
                    if(null != swancsSystemMenuView) swancsSystemMenuView.clearAllMenu();

                }
            }
        } else if(-1 == position) {


            //当menuTips 和 menuTipView 不一致时，强制同步数据，以menuTips为准

            String removeMenuCode = !swancsSystemTips.commonMenu() ? swancsSystemTips.menuCode : swancsSystemTips.getMainUrl();

            SwancsSystemTipsBean nextShowTip= (null == menuTips || menuTips.isEmpty()) ? null : menuTips.get(menuTips.size() - 1);

            String nnextMenuCode = null;
            if(null== nextShowTip){

                nnextMenuCode = null;
            } else {
                nnextMenuCode = !nextShowTip.commonMenu() ? nextShowTip.menuCode : nextShowTip.getMainUrl();
            }

            if(TextUtils.isEmpty(removeMenuCode)){

                //拿到当前打开的标签
                removeMenuCode = getOpenedMenuTipView();
            }

            removeTipView(removeMenuCode, nnextMenuCode);

            if(null!=nextShowTip && !swancsSystemTips.menuTipEquals(nextShowTip)) {

                int nextMenuPosition = getMenuNewPosition(nextShowTip);

                switchMenu(nextMenuPosition, nextShowTip.getShowUrl());
            }

            if(null == menuTips || menuTips.isEmpty()){

                //收缩系统菜单
                swancsSystemMenuView = getSystemMenuCompontent();
                if(null != swancsSystemMenuView) swancsSystemMenuView.clearAllMenu();

            }

        }


    }

    //找到打开标签页的menucode
    private String getOpenedMenuTipView(){
        if(null == menuTipsL && 0 == menuTipsL.getChildCount()){

            return null;
        }

        for(int i=0; i<menuTipsL.getChildCount(); i++) {

            RelativeLayout childView = (RelativeLayout) menuTipsL.getChildAt(i);

            if (null != childView && (boolean)(childView.getTag(R.id.menu_status))) {

                return (String)(childView.getTag(R.id.menu_code));
            }
        }


        return null;
    }

    private int getMenuNewPosition(SwancsSystemTipsBean nextSystemTips){
        if(null == nextSystemTips || null == menuTips || menuTips.isEmpty()){
            return -1;
        }


        for(SwancsSystemTipsBean swancsSystemTip : menuTips){

            if(null != swancsSystemTip && swancsSystemTip.menuTipEquals(nextSystemTips)){
                return menuTips.indexOf(swancsSystemTip);
            }
        }



        return -1;



    }

    private WxSwancsSystemMenuView getSystemMenuCompontent(){

        if(null == swancsSystemMenuView){

            swancsSystemMenuView = ReflectUtils.getComponent(WxSwancsSystemMenuView.mInstanceId, WxSwancsSystemMenuView.mRef);
        }

        return swancsSystemMenuView;
    }

    private SwancsMenuRemoveTip removeTips(SwancsSystemTipsBean swancsSystemTip){

        if(null == swancsSystemTip || null == menuTips || menuTips.isEmpty()) return null;

        SwancsMenuRemoveTip removeTip = new SwancsMenuRemoveTip();
        SwancsSystemTipsBean currentSwanTip = null;

        SwancsSystemTipsBean newMenu = null;
        String removeMenuCode = !swancsSystemTip.commonMenu() ? swancsSystemTip.menuCode : swancsSystemTip.getMainUrl();

        int size = menuTips.size();
        for(int i =0; i< size; i++){

            SwancsSystemTipsBean subMenuTip = menuTips.get(i);

            if(null!=subMenuTip
                    && subMenuTip.menuTipEquals (swancsSystemTip)){

                if(swancsSystemTip.menuTopsStatus){
                    if(size > 1){

                        SwancsSystemTipsBean nextTips = null;

                        if(i == 0){
                            nextTips = menuTips.get(i + 1);
                        } else if(i > 0 && i < size){

                            nextTips = menuTips.get(i - 1);
                        }

                        if(null != nextTips) {

                            nextTips.menuTopsStatus = true;
                            newMenu = nextTips;
                        }
                    }
                }

                currentSwanTip = menuTips.get(i);

                removeTip.removeUrl = currentSwanTip.getMainUrl();
            }

        }

        removeTipView(removeMenuCode, (null == newMenu) ? "" : !newMenu.commonMenu() ? newMenu.menuCode : newMenu.getMainUrl());

        clearTipUrls(currentSwanTip);

        if(null != newMenu){

            swancsSystemMenuView = getSystemMenuCompontent();
            //改成组件获取
            if(null != swancsSystemMenuView
                    && null!=newMenu
                    && !newMenu.commonMenu()) swancsSystemMenuView.searchMenu(newMenu.menuCode, false);

            removeTip.nextSwancsSystemTip = newMenu;

            return removeTip;
        } else {

            SwancsSystemTipsBean newMenuShow = null;

            //切换新的界面
            if(null!=menuTips && !menuTips.isEmpty()){

                for(SwancsSystemTipsBean newTips : menuTips){

                    if(null != newTips){

                        if(null == newMenu){

                            if(newTips.menuTopsStatus){

                                //switchMenu(menuTips.indexOf(newTips), newTips.menuSkipUrl);

                                //改成组件获取

                                swancsSystemMenuView = getSystemMenuCompontent();
                                if(null != swancsSystemMenuView
                                        && null!=newTips && !newTips.commonMenu()) swancsSystemMenuView.searchMenu(newTips.menuCode, false);
                                removeTip.nextSwancsSystemTip = newTips;

                                return removeTip;
                            }

                        } else {

                            if(null!=newTips && newTips.menuTipEquals(newMenu)){

                                if(!newTips.menuTopsStatus){
                                    newTips.menuTopsStatus = true;
                                }


                                newMenuShow = newTips;
                            } else {

                                if(newTips.menuTopsStatus){
                                    newTips.menuTopsStatus = false;
                                }
                            }

                        }
                    }

                }

                //改成组件获取
                        swancsSystemMenuView = getSystemMenuCompontent();
                        if(null != swancsSystemMenuView
                                && null!=newMenuShow
                                && !newMenuShow.commonMenu()) swancsSystemMenuView.searchMenu(newMenuShow.menuCode, false);

                        removeTip.nextSwancsSystemTip = newMenuShow;

                        return removeTip;

            }

            return removeTip;

        }
    }

    private void clearTipUrls(SwancsSystemTipsBean swancsSystemTip){

        if(null == menuTips || menuTips.isEmpty()) return;

        if(null!=swancsSystemTip){

            if(null!=swancsSystemTip.urls && !swancsSystemTip.urls.isEmpty()){

                for(TipsInUrlBean tipsInUrl : swancsSystemTip.urls){

                    //兼容杭小宝相关页面关闭，清除杭小宝信息
                    if(null!=tipsInUrl){
                        GlobalConstant.removeCustomInfoPage(tipsInUrl.url);
                    }
                }

                swancsSystemTip.urls.clear();
            }

            menuTips.remove(swancsSystemTip);
        }

    }

    private void removeTipView(String removedMenuCode, String nextMenuCode){

        try {

            if(TextUtils.isEmpty(removedMenuCode)){
                return;
            }

            if(null == menuTipsL || 0 == menuTipsL.getChildCount()){

                return;
            }

            HLogger.logWithTag("SystemMenuCustomer", "下一个打开的菜单码="+nextMenuCode);

            for(int i=0; i<menuTipsL.getChildCount(); i++){

                RelativeLayout childView = (RelativeLayout) menuTipsL.getChildAt(i);

                if(null!=childView){

                    HLogger.logWithTag("SystemMenuCustomer", "删除菜单----菜单码="+((null!=childView) ? String.valueOf(childView.getTag(R.id.menu_code)) : "空"));

                    if(TextUtils.equals((String)childView.getTag(R.id.menu_code), removedMenuCode)){

                        menuTipsL.removeViewAt(i);

                        HLogger.logWithTag("SystemMenuCustomer", "删除菜单，下标="+i);
                        i --;

                    }else if(!TextUtils.isEmpty(nextMenuCode)
                            && TextUtils.equals((String)childView.getTag(R.id.menu_code), nextMenuCode)) {

                        childView.setBackground(getContext().getResources().getDrawable(R.drawable.drawable_menu_open_bg));

                        for(int j =0; j < childView.getChildCount(); j++){

                            View childInnerView = childView.getChildAt(j);
                            if(childInnerView instanceof TextView){
                                ((TextView)childInnerView).setTextColor(Color.parseColor("#333333"));
                            } else if(childInnerView instanceof ImageView){

                                ((ImageView)childInnerView).setBackground(getContext().getResources().getDrawable(R.drawable.ic_menu_close_black));
                            }
                        }

                        childView.setTag(R.id.menu_status, true);
                    }
                }

            }

        }catch (Exception e){
            e.printStackTrace();
        }
    }

    private void removeMenuHandleDelay(int index, SwancsSystemTipsBean swancsSystemTip, String url, String[] urlInTip, boolean isManual, boolean shouldSendParams, boolean closeTip, PageRemovedCallback pageRemovedCallback){
        if(TextUtils.isEmpty(url)){

            return;
        }

        this.pageRemovedCallback = pageRemovedCallback;

        this.urlInRemoveTip = urlInTip;


        if(isManual || shouldSendParams){

            //关闭之前给前端传一下关闭的url
            Map<String, Object> params = new HashMap<>(1<<1);
            params.put("removeUrl", url);
            params.put("urlInTip", (null == this.urlInRemoveTip) ?"":this.urlInRemoveTip);
            params.put("type", (null == swancsSystemTip) ? "1" : (swancsSystemTip.getPageSuccessStatus() ? "2": "1"));
            fireEvent("Swancs_Menu_Remove", params);

        } else if(!isManual && !shouldSendParams && closeTip){
            //不是手动，不是成功页面
            Map<String, Object> params = new HashMap<>(1<<1);
            params.put("removeUrl", url);
            params.put("urlInTip", (null == this.urlInRemoveTip) ?"":this.urlInRemoveTip);
            params.put("type", "3");
            fireEvent("Swancs_Menu_Remove", params);
        }

        if(null!=swancsSystemTip) swancsSystemTip.resetPageSuccessStatus();

        


        removeMenu(index, url);

    }

    private String[] getUrlInTip(SwancsSystemTipsBean preRemoveMenuTip){

        if(null != preRemoveMenuTip){

            LinkedList<TipsInUrlBean> urls = preRemoveMenuTip.urls;
            
            if(null == urls || urls.isEmpty()){

                return new String[]{};
            }

            List<String> subUrls = new ArrayList<>();

            for(TipsInUrlBean tipsInUrl : urls){

                if(null!=tipsInUrl) subUrls.add(tipsInUrl.url);
            }

            if(null == subUrls || subUrls.isEmpty()){
                return new String[]{};
            } else {

                return subUrls.toArray(new String[subUrls.size()]);
            }

        }

        return new String[]{};
    }


    @JSMethod(uiThread = true)
    public void removeMenu(int index, String url) {

        if(TextUtils.isEmpty(url)){

            return;

        }

        HLogger.logWithTag("MenuModuleView_New", "removeMenu()，url="+url);

        HLogger.logWithTag("MenuModuleView", "渲染进程-删除="+Thread.currentThread().getName());

        WriteLogUtil.getInstance().saveLoaclSystemMenuLog("执行-JSMethod-removeMenu" + "\n");

        //关闭界面前先判断当前界面是否渲染完成
//        if(!pagerIsRendered(url)){
//
//            ToastUtils.showShort(getContext(), "当前页面未渲染完成，无法关闭");
//
//            return;
//        }

//        //关闭之前给前端传一下关闭的url
//        Map<String, Object> params = new HashMap<>(1<<1);
//        params.put("removeUrl", url);
//        params.put("urlInTip", (null == this.urlInRemoveTip) ?"":this.urlInRemoveTip);
//        params.put("type", getCloseType());
//        fireEvent("Swancs_Menu_Remove", params);


        HLogger.logWithTag("MenuModuleView", "删除菜单标签的url集合"+((null == this.urlInRemoveTip) ?"":JSON.toJSONString(this.urlInRemoveTip)));
        mHandler = createHandler();
        
        mHandler.postDelayed(() -> {

            hideAllFragment(hashMap);//add进来，如果只是移除当前之前的页面会重叠
            FragmentTransaction transaction = mSupportFragmentManager.beginTransaction();
            for (Map.Entry<String, Fragment> entry : hashMap.entrySet()) {
                String key = entry.getKey();
                Fragment fragment = entry.getValue();
                if (TextUtils.equals(key, url)) {
                    transaction.hide(fragment);
                    transaction.remove(fragment);
                    transaction.commitAllowingStateLoss();
                    Fragment wxFragment = hashMap.remove(key);
                    if(null!=wxFragment){
                        HLogger.logWithTag("MenuModuleView", "销毁移出菜单的fragment");
                        if(wxFragment instanceof WeexPageFragment){
                            ((WeexPageFragment)wxFragment).destroyWeex();
                            HLogger.logWithTag("MenuModuleView", "销毁weex - fragment");
                        }
                        wxFragment = null;
                    }


                    break;
                }
            }

            //删除tip的url
            removeMenuTips(url);
            Log.i("switchMenu","移出菜单==index="+index+", url="+url);

            GlobalConstant.removeCustomInfoPage(url);

            if(null!=this.pageRemovedCallback){
                HLogger.logWithTag("MenuModuleView", "页面删除回调执行");
                this.pageRemovedCallback.pageRemoved();
            }

            this.urlInRemoveTip = null;
        }, 500);
        return;
    }

    private void removeMenuTips(String url){

        if(TextUtils.isEmpty(url)) return;

        //第一次数据校准
        if(null == menuTips || menuTips.isEmpty()) {
            if(null!=hashMap) hashMap.clear();

            return;
        }

        SwancsSystemTipsBean currentMenuTip = null;
        List<TipsInUrlBean> removedUrls = new LinkedList<>();

        for(SwancsSystemTipsBean swancsSystemTip : menuTips){

            if(null!=swancsSystemTip && null!=swancsSystemTip.urls && !swancsSystemTip.urls.isEmpty()){

                int size = swancsSystemTip.urls.size();

                for(int i=0; i<size; i++){

                    TipsInUrlBean tipsInUrl = swancsSystemTip.urls.get(i);

                    if(null != tipsInUrl && TextUtils.equals(tipsInUrl.url, url)){

                        currentMenuTip = swancsSystemTip;
                        removedUrls.addAll(currentMenuTip.urls.subList(i, currentMenuTip.urls.size()));
                    }
                }
            }

        }

        if(null != removedUrls && !removedUrls.isEmpty()){

            currentMenuTip.urls.removeAll(removedUrls);
        }

        if(null != currentMenuTip
                && !TextUtils.isEmpty(currentMenuTip.getLastUrl())){

            //判断是否存在跨业务，如果存在，则切换标签
            //https://ceph.swancs.hzbtest:7480/emas-cdn/app/hzbank-defray6/pages/CNAPS2/electricTicketCentralisedPaymentCheck/entry.js?menuCode=22241

            String skipUrl = currentMenuTip.getLastUrl();
            String menuCode = skipUrl.substring(skipUrl.indexOf("menuCode=") + 9);
            if(!TextUtils.isEmpty(menuCode) && !TextUtils.equals(menuCode, currentMenuTip.menuCode)){

                //需要更新菜单标签信息
                SwancsSystemBean swancSysytemMenuNew =  null;
                swancSysytemMenuNew = SwancsSystemMenuManager.getDefault().searchMenuByCode(menuCode);
                if(null == swancSysytemMenuNew){

                    String menuUrl = skipUrl.substring(url.indexOf("pages/") + 6, url.indexOf("/entry.js"));

                    swancSysytemMenuNew = SwancsSystemMenuManager.getDefault().searchMenuByMenuUrl(menuUrl);
                }

                if(null != swancSysytemMenuNew && !TextUtils.equals(swancSysytemMenuNew.menuCode, currentMenuTip.menuCode)){

                    //替换标签
                    changeMenuTip(currentMenuTip.menuCode, swancSysytemMenuNew, skipUrl);
                }

            }

            showMenu(currentMenuTip.getLastUrl());
        }

        //第二次数据校准
        menuUrlCalibra();
    }

    @JSMethod(uiThread = true)
    public void closeAllMenu() {
        
        try{

            //删除全部菜单
            HLogger.logWithTag("MenuModuleView", "closeAllMenu---清除全部菜单");

            if(null == menuTips || menuTips.isEmpty()){
                return;
            }

            //删除全部的标签view
            if(null == menuTipsL || 0 == menuTipsL.getChildCount()){

                return;
            }

            menuTipsL.removeAllViews();

            //移除url对应的fragment

            if(null == hashMap || hashMap.isEmpty()){

                return;
            }

            Set<String> keys = hashMap.keySet();
            if(null == keys || keys.isEmpty()){

                return;
            }


            WriteLogUtil.getInstance().saveLoaclSystemMenuLog("执行-JSMethod-closeAllMenu" + "\n");
            
            String[] keyArr = keys.toArray(new String[keys.size()]);

            HLogger.logWithTag("MenuModuleView", "hashMap的size=" + hashMap.size());
            HLogger.logWithTag("MenuModuleView", "key的size=" + keyArr.length);

            similarCycle(keyArr, 0);

            return;

        }catch (Exception e){

            e.printStackTrace();

            HLogger.logWithTag("MenuModuleView", (null == e) ? "无异常信息" :e.getMessage());
        }

        return;
    }

    public SwancsSystemTipsBean getMenuTipByUrl(String url){

        if(TextUtils.isEmpty(url) || null == menuTips || menuTips.isEmpty()) return null;

        for(SwancsSystemTipsBean swancsSystemTip : menuTips){

            if(null!=swancsSystemTip && null != swancsSystemTip.urls && !swancsSystemTip.urls.isEmpty()){

                for(TipsInUrlBean tipsInUrl : swancsSystemTip.urls){

                    if(null!=tipsInUrl && TextUtils.equals(tipsInUrl.url, url)){
                        
                        return swancsSystemTip;
                    }
                }
            }
        }



        return null;

    }

    private String[] changeUrls(LinkedList<TipsInUrlBean> urls){
        
        if(null == urls || urls.isEmpty()) return null;

        LinkedList<String> onlyUrls = new LinkedList<>();

        for(TipsInUrlBean tipsInUrl : urls){
            if(null!=tipsInUrl){
                onlyUrls.add(tipsInUrl.url);
            }
        }

        if(null!=onlyUrls && !onlyUrls.isEmpty()) return onlyUrls.toArray(new String[onlyUrls.size()]);

        return null;
    }

    //模拟循环，weex交互方法中，for循环报反射错误
    private void similarCycle(String[] urls, final int position){

        if(null!=urls && urls.length > 0 &&  position > -1 && position < urls.length){

            HLogger.logWithTag("MenuModuleView", "position=" + position);

            HLogger.logWithTag("MenuModuleView", "urls=" + JSON.toJSONString(urls));

            SwancsSystemTipsBean swancsSystemTip = getMenuTipByUrl(urls[position]);

            removeMenuHandleDelay(-1, swancsSystemTip, urls[position], (null==swancsSystemTip) ? null : changeUrls(swancsSystemTip.urls), false,  true, true, new PageRemovedCallback() {
                @Override
                public void pageRemoved() {
                    int index = position + 1;
                    similarCycle(urls, index);
                }
            });
        } else {

            HLogger.logWithTag("MenuModuleView", "finally=执行finally");

            if(null!=menuTips){
                menuTips.clear();

                menuTips = null;
            }

            if(null!=hashMap){

                hashMap.clear();
            }

            swancsSystemMenuView = getSystemMenuCompontent();
            if(null != swancsSystemMenuView) swancsSystemMenuView.clearAllMenu();
        }
    }

    @JSMethod(uiThread = true)
    public void openMenuByCode(String menuCode) {
        HLogger.logWithTag("MenuModuleView", "openMenuByCode---menuCode="+menuCode);
        
        if(TextUtils.isEmpty(menuCode)){

            return;
        }

        WriteLogUtil.getInstance().saveLoaclSystemMenuLog("执行--JSMethod--openMenuByCode---menuCode="+menuCode + "\n");

        SwancsSystemBean swancsSystem = SwancsSystemMenuManager.getDefault().searchMenuByCode(menuCode);

        if(null != swancsSystem){

            mHandler = createHandler();
            mHandler.postDelayed(() -> {
                showMenu(swancsSystem, false, null);
            }, 500);
        }

        return;

    }

    private boolean shouleFilterMenuType(SwancsSystemBean swancsSystem){

        if(null!=swancsSystem
                && !TextUtils.isEmpty(swancsSystem.transType)
                && (TextUtils.equals("A", swancsSystem.transType) || TextUtils.equals("T", swancsSystem.transType))) return true;

        return false;
    }

    private void shouldUpdateCurMenuTag(SwancsSystemBean swancsSystem, String url){

        if(null == swancsSystem) return;

        SwancsSystemTipsBean swancsSystemTipOpen = getOpenedMenuTip(null);
        
        if(null!=swancsSystemTipOpen
                && !TextUtils.equals(swancsSystemTipOpen.menuCode, swancsSystem.menuCode)){

            //先替换标签

            //再替换menuTips对象

            swancsSystemTipOpen.resetPageSuccessStatus();

            changeMenuTip(swancsSystemTipOpen.menuCode, swancsSystem, url);
        }
    }

    private void changeMenuTip(String menuCode, SwancsSystemBean swancsSystem, String url){
        
        if(TextUtils.isEmpty(menuCode) || null == swancsSystem){

            return;
        }

        if(null == menuTipsL || 0 == menuTipsL.getChildCount() || null == menuTips || menuTips.isEmpty()){

            return;
        }

        //更新菜单标签

        SwancsSystemTipsBean replaceTip = changeMenu(swancsSystem, url);

        //更新本地缓存
        for(SwancsSystemTipsBean swancsSystemTip : menuTips){

            if(null!=swancsSystemTip &&TextUtils.equals(swancsSystemTip.menuCode, menuCode)){

                //把原来的url设置到新的菜单标签中
                if(!swancsSystemTip.urls.isEmpty()){

                    replaceTip.addChangeUrls(swancsSystemTip.urls);

                }

                menuTips.set(menuTips.indexOf(swancsSystemTip), replaceTip);
            }
        }

        HLogger.logWithTag("MenuModuleView", "菜单标签切换后的链接集合="+((null == replaceTip.urls || replaceTip.urls.isEmpty()) ? "无数据" : JSON.toJSONString(replaceTip.urls)));

        //reloadTipView
        for(int i=0; i< menuTipsL.getChildCount(); i++){

            RelativeLayout childView = (RelativeLayout) menuTipsL.getChildAt(i);

            if(null!=childView){

                if((boolean)(childView.getTag(R.id.menu_status))
                        && TextUtils.equals(menuCode, (String)childView.getTag(R.id.menu_code))){

                    for(int j =0; j < childView.getChildCount(); j++){

                        View childInnerView = childView.getChildAt(j);
                        if(childInnerView instanceof TextView){

                            TextView menuNameTx = (TextView) childInnerView;
                            menuNameTx.setText(swancsSystem.menuName);


                            menuNameTx.setOnClickListener(null);
                            menuNameTx.setOnClickListener(v -> {

                                //切换菜单

                                switchMenu(replaceTip);
                            });


                        } else if(childInnerView instanceof ImageView){

                            ImageView menuClose = (ImageView) childInnerView;

                            menuClose.setOnClickListener(null);

                            menuClose.setOnClickListener(new ClickProxy(v -> {

                                boolean isSuccess = replaceTip.getPageSuccessStatus();
                                //关闭菜单
                                removeMenu(replaceTip, isSuccess, true, null);

                            }));

                            //长按强制删除
                            menuClose.setOnLongClickListener(new View.OnLongClickListener() {
                                @Override
                                public boolean onLongClick(View v) {

                                    //关闭菜单
                                    removeMenu(replaceTip, false, true, null);
                                    return true;
                                }
                            });
                        }
                    }


                    childView.setTag(R.id.menu_code, swancsSystem.menuCode);
                }
            }

        }

    }

    @JSMethod(uiThread = true)
    public void openMenu(String url, boolean openLabel, String labelName) {

        WriteLogUtil.getInstance().saveLoaclSystemMenuLog("执行--JSMethod--openMenu---url="+url+"openLabel="+openLabel+"labelName="+labelName + "\n");
        HLogger.logWithTag("MenuModuleView", "openMenu---url="+url+"--是否新开标签="+openLabel);
        if(!openLabel){

            //界面内部跳转，不新开标签

            String menuUrl = url.substring(url.indexOf("pages/") + 6, url.indexOf("/entry.js"));
            
            if(!TextUtils.isEmpty(menuUrl)){

                HLogger.logWithTag("MenuModuleView", "openMenu---menuUrl="+menuUrl);

                SwancsSystemBean swancsSystem = SwancsSystemMenuManager.getDefault().searchMenuByMenuUrl(menuUrl);

                if(null!=swancsSystem){
                    
                    //判断打开的菜单是否和当前展示的菜单标签一致，不一致则更新菜单标签
                    url = url + "&menuCode="+swancsSystem.menuCode;

                    shouldUpdateCurMenuTag(swancsSystem, url);

                    showMenu(url);
                } else {

                    //从当前主链接获取menuCode
                    SwancsSystemTipsBean swancsSystemTipOpen = getOpenedMenuTip(null);
                    if(null != swancsSystemTipOpen){

                        swancsSystemTipOpen.resetPageSuccessStatus();
                        url = url + "&menuCode="+swancsSystemTipOpen.menuCode;
                        showMenu(url);
                    } else {

                        showMenu(url);
                    }
                }

            } else {

                showMenu(url);
                
            }
        } else {

            //界面内部跳转，新开标签
            if(!TextUtils.isEmpty(url)){

                //先根据url拿到菜单的menuUrl  pages/   和  /entry.js之间

                SwancsSystemBean swancsSystem = null;
                String params = url.substring(url.indexOf("/entry.js?") + 10);

                String menuUrl = url.substring(url.indexOf("pages/") + 6, url.indexOf("/entry.js"));
                if(TextUtils.isEmpty(menuUrl)){
                    //不是正常的系统菜单
                    swancsSystem = new SwancsSystemBean();
                    swancsSystem.module = "";
                    swancsSystem.menuUrl = "";
                    swancsSystem.menuCode = "";
                    swancsSystem.menuName = labelName;
                    swancsSystem.transType = "";

                    showMenu(swancsSystem, url, false);

                } else {
                    //根据menuUrl 在 系统菜单树里面筛选
                    swancsSystem = SwancsSystemMenuManager.getDefault().searchMenuByMenuUrl(menuUrl);

                    if(null!=swancsSystem){
                       if (TextUtils.isEmpty(params)){
                           showMenu(swancsSystem, false, url);
                       } else {
                           showMenuParams(swancsSystem, params, false, url);
                       }
                    }else {

                        //不是正常的系统菜单
                        swancsSystem = new SwancsSystemBean();
                        swancsSystem.module = "";
                        swancsSystem.menuUrl = "";
                        swancsSystem.menuCode = "";
                        swancsSystem.menuName = labelName;
                        swancsSystem.transType = "";

                        showMenu(swancsSystem, url, false);

                    }

                }

            }

        }

        return;
    }

    private String getParamsByObj(JSONObject paramObj){

        if(null == paramObj) return null;

        try{

            Map<String, String> paramMap =JSON.parseObject(JSON.toJSONString(paramObj), HashMap.class);

            if(null==paramMap || paramMap.isEmpty()) return null;

            StringBuffer buffer = new StringBuffer();

            for(String key : paramMap.keySet()){

                buffer.append("&");
                buffer.append(key);
                buffer.append("=");
                buffer.append(String.valueOf(paramMap.get(key)));
            }

            return buffer.toString();

        }catch (Exception e){
            return null;
        }
    }

    @JSMethod(uiThread = true)
    public void closeMenu(String url, boolean closeLabel, boolean continuous, String suggestTrans) {

        HLogger.logWithTag("MenuModuleView", "closeMenu---url="+url+"--是否关闭标签="+closeLabel+"---是否继续交易="+continuous+"建议交易参数="+suggestTrans);

        WriteLogUtil.getInstance().saveLoaclSystemMenuLog("执行--JSMethod--closeMenu---url="+url+"closeLabel="+closeLabel+"continuous="+continuous+"suggestTrans="+suggestTrans + "\n");

        SwancsSystemTipsBean swancsSystemTip = getOpenedMenuTip(url);

        if(null==swancsSystemTip){

            swancsSystemTip = getOpenedMenuTip();
        }

        if(null == swancsSystemTip){

            return;
        }

        String menuParamStr = null;



        //判断是否存在建议交易

        if(TextUtils.isEmpty(suggestTrans)){

            closedSwancsSystem = swancsSystemTip.swancsSystem;

            //记录当前的菜单和连接
            if(null == closedSwancsSystem && !swancsSystemTip.commonMenu()){

                closedSwancsSystem = SwancsSystemMenuManager.getDefault().searchMenuByCode(swancsSystemTip.menuCode);

                HLogger.logWithTag("MenuModuleView", "标签内置系统菜单对象不存在，重新获取");
            }
        } else {

            try{

                JSONObject suggestOb = JSONObject.parseObject(suggestTrans);

                if(null!=suggestOb.getBoolean("openSelf") && suggestOb.getBoolean("openSelf")){

                    continuous = true;

                    //连续交易
                    JSONObject menuCodeOb = suggestOb.getJSONObject("param");
                    menuParamStr = getParamsByObj(menuCodeOb);

                    HLogger.logWithTag("MenuModuleView", "连续交易额外参数="+((TextUtils.isEmpty(menuParamStr))?"无":menuParamStr));


                    closedSwancsSystem = swancsSystemTip.swancsSystem;

                    //记录当前的菜单和连接
                    if(null == closedSwancsSystem && !swancsSystemTip.commonMenu()){

                        closedSwancsSystem = SwancsSystemMenuManager.getDefault().searchMenuByCode(swancsSystemTip.menuCode);

                        HLogger.logWithTag("MenuModuleView", "标签内置系统菜单对象不存在，重新获取");
                    }
                } else if(null==suggestOb.getBoolean("openSelf") || !suggestOb.getBoolean("openSelf")){

                    String menuUrl = suggestOb.getString("page");
                    String menuName = suggestOb.getString("pageName");
                    String module = suggestOb.getString("moduleName");
                    JSONObject menuCodeOb = suggestOb.getJSONObject("param");

                    menuParamStr = getParamsByObj(menuCodeOb);

                    String menuCode;

                    if(null == menuCodeOb){
                        menuCode = null;
                    } else {

                        menuCode = menuCodeOb.getString("menuCode");
                    }

                    if(!TextUtils.isEmpty(menuUrl)
                            && !TextUtils.isEmpty(menuName)
                            && !TextUtils.isEmpty(module)
                            && !TextUtils.isEmpty(menuCode)){

                        closedSwancsSystem = new SwancsSystemBean();
                        closedSwancsSystem.menuUrl = menuUrl;
                        closedSwancsSystem.menuName = menuName;
                        closedSwancsSystem.module = module;
                        closedSwancsSystem.menuCode = menuCode;
                    } else if(!TextUtils.isEmpty(menuUrl)
                            && TextUtils.isEmpty(menuCode)){

                        closedSwancsSystem = SwancsSystemMenuManager.getDefault().searchMenuByMenuUrl(menuUrl);
                    } else if(TextUtils.isEmpty(menuUrl)
                            && !TextUtils.isEmpty(menuCode)){

                        closedSwancsSystem = SwancsSystemMenuManager.getDefault().searchMenuByCode(menuCode);
                    }


                }


            }catch (Exception e){
                e.printStackTrace();

                closedSwancsSystem = swancsSystemTip.swancsSystem;

                //记录当前的菜单和连接
                if(null == closedSwancsSystem && !swancsSystemTip.commonMenu()){

                    closedSwancsSystem = SwancsSystemMenuManager.getDefault().searchMenuByCode(swancsSystemTip.menuCode);

                    HLogger.logWithTag("MenuModuleView", "标签内置系统菜单对象不存在，重新获取");
                }
            }
        }

        //如果当前是成功界面则发送参数

        boolean isSuccess = swancsSystemTip.getPageSuccessStatus();

        if(closeLabel){

            //关闭菜单标签后，删除显示的链接
            boolean finalContinuous = continuous;
            String finalMenuParamStr = menuParamStr;

            //关闭标签
            removeMenu(swancsSystemTip, isSuccess, false,  new PageSwitchedCallback() {
                @Override
                public void PageSwitchedCallback() {

                    if(finalContinuous){

                        if(null!=closedSwancsSystem){

                            if(TextUtils.isEmpty(finalMenuParamStr)){

                                showMenu(closedSwancsSystem, shouleFilterMenuType(closedSwancsSystem), null);

                            }else {

                                showMenuParams(closedSwancsSystem, finalMenuParamStr, shouleFilterMenuType(closedSwancsSystem),  null);

                            }
                        }
                    }

                    if(null != pageSwitchedCallback){
                        pageSwitchedCallback = null;
                    }
                }
            });

        } else {


            //关闭菜单标签后，删除显示的链接
            if(null!=swancsSystemTip.urls
                    && !swancsSystemTip.urls.isEmpty()){

                //如果当前的标签只存在一个url，则先关闭标签，后关闭该url
                if(swancsSystemTip.urls.size() == 1){

                    //关闭菜单标签后，删除显示的链接
                    boolean finalContinuous1 = continuous;

                    String finalMenuParamStr = menuParamStr;

                    //关闭标签
                    removeMenu(swancsSystemTip, isSuccess, false, new PageSwitchedCallback() {
                        @Override
                        public void PageSwitchedCallback() {

                            if(finalContinuous1){

                                if(null!=closedSwancsSystem){

                                    if(TextUtils.isEmpty(finalMenuParamStr)){

                                        showMenu(closedSwancsSystem, shouleFilterMenuType(closedSwancsSystem), null);

                                    }else {

                                        showMenuParams(closedSwancsSystem, finalMenuParamStr, shouleFilterMenuType(closedSwancsSystem),  null);

                                    }
                                }
                            }

                            if(null != pageSwitchedCallback){
                                pageSwitchedCallback = null;
                            }
                        }
                    });

                } else {

                    //强制重置界面的是否成功过值 为 false
                    if(null != swancsSystemTip) swancsSystemTip.resetPageSuccessStatus();

                    String[] urlInRemoveTip = getUrlInTip(swancsSystemTip);

                    for(TipsInUrlBean tipsInUrl : swancsSystemTip.urls){

                        if(null!=tipsInUrl
                                && tipsInUrl.isShow){

                            boolean finalContinuous2 = continuous;

                            String finalMenuParamStr = menuParamStr;


                            removeMenuHandleDelay(-1, swancsSystemTip, tipsInUrl.url, urlInRemoveTip,  false, false, false, new PageRemovedCallback() {
                                @Override
                                public void pageRemoved() {

                                    if(finalContinuous2){

                                        if(null!=closedSwancsSystem){

                                            if(TextUtils.isEmpty(finalMenuParamStr)){

                                                showMenu(closedSwancsSystem, shouleFilterMenuType(closedSwancsSystem), null);

                                            }else {

                                                showMenuParams(closedSwancsSystem, finalMenuParamStr, shouleFilterMenuType(closedSwancsSystem),  null);

                                            }
                                        }


                                    }

                                    if(null != MenuModuleView.this.pageRemovedCallback){
                                        MenuModuleView.this.pageRemovedCallback = null;
                                    }
                                }
                            });
                            break;
                        }
                    }
                }
            }
        }

        HLogger.logWithTag("MenuModuleView", "closeMenu---结束");


        return;
    }

    private void menuUrlCalibra(){

        if(null == menuTips || menuTips.isEmpty()){
            if(null!=hashMap) hashMap.clear();

            return;
        }

        LinkedList<TipsInUrlBean> urlExist = getExistMenuUrl();

        if(null == urlExist || urlExist.isEmpty()){
            if(null!=hashMap) hashMap.clear();

            return;
        }

        Iterator<Map.Entry<String, Fragment>> it = hashMap.entrySet().iterator();
        if(null!=it){

            while (it.hasNext()){

                Map.Entry<String, Fragment> entery = it.next();

                if(null!=entery){

                    int position = -1;

                    for(TipsInUrlBean tipsInUrl : urlExist){

                        if(null!=tipsInUrl && TextUtils.equals(tipsInUrl.url, entery.getKey())){
                            position += 1;
                        }

                    }

                    if(position == -1) it.remove();
                }

            }
        }

    }

    private LinkedList getExistMenuUrl(){

        if(null== menuTips || menuTips.isEmpty()) return null;

        LinkedList<TipsInUrlBean> existUrl = new LinkedList<>();

        for(SwancsSystemTipsBean swancsSystemTip : menuTips){

            if(null!=swancsSystemTip && null!=swancsSystemTip.urls&&!swancsSystemTip.urls.isEmpty()){

                existUrl.addAll(existUrl.size(), swancsSystemTip.urls);
            }
        }

        return existUrl;

    }


    public Fragment createFragment(String jsSource) {

        if(TextUtils.isEmpty(jsSource)){

            return null;
        }

        HLogger.writeLogOnDisk("MenuModuleView", "jsSource1", "jsSource1 = " +jsSource);

        boolean iswork = DynamicSdk.getInstance().isSdkWork();
        if (iswork){
            jsSource = DynamicSdk.getInstance().redirectUrl(jsSource);

            HLogger.writeLogOnDisk("MenuModuleView", "jsSource2", "jsSource2 = " +jsSource);
        }

        String renderUrl = getRenderUrl(jsSource);
        if(TextUtils.isEmpty(renderUrl)){

            return null;
        }

        HLogger.writeLogOnDisk("MenuModuleView", "renderUrl", "renderUrl = " +renderUrl);

        WeexPageFragment fragment = (WeexPageFragment) WeexPageFragment.newInstance(getContext(), WeexFragment.class, jsSource, renderUrl);
        fragment.setProgressBarView(new HWxProgressBar(HWxProgressBar.PROGRESS_GIF));
        return fragment;
    }

    public String getRenderUrl(String url) {

        if (TextUtils.isEmpty(url)) {
            return null;
        }

        String result = url;
        Uri uri = Uri.parse(url);
        String tpl = uri.getQueryParameter(EmasWeex.URL_PARAM);
        if (!TextUtils.isEmpty(tpl)) {
            Uri.Builder tplBuilder = Uri.parse(tpl).buildUpon();
            Set<String> queries = uri.getQueryParameterNames();
            if (queries != null && queries.size() > 0) {

                for (String param : queries) {
                    if (!EmasWeex.URL_PARAM.equals(param)) {
                        tplBuilder.appendQueryParameter(param, uri.getQueryParameter(param));
                    }
                }
            }
            result = tplBuilder.toString();
        }
        return result;
    }

    @Override
    public void onActivityDestroy() {
        super.onActivityDestroy();
        if(hashMap!=null && !hashMap.isEmpty()){
            hashMap.clear();
            hashMap = null;
        }

        if(null!=menuTips && !menuTips.isEmpty()){

            for(SwancsSystemTipsBean swancsSystemTip : menuTips){

                if(null!=swancsSystemTip && null!=swancsSystemTip.urls && !swancsSystemTip.urls.isEmpty()){

                    swancsSystemTip.urls.clear();
                    swancsSystemTip.urls = null;
                }

            }
            menuTips.clear();
            menuTips = null;
        }

        if(null!=mHandler){
            mHandler.removeCallbacksAndMessages(null);
            mHandler = null;
        }

        if(null!=hDialog){
            hDialog.cancel();
            hDialog = null;
        }

        if(null!=this.pageRemovedCallback){

            this.pageRemovedCallback = null;
        }

        if(null!=mInstanceId){
            mInstanceId = null;
        }

        if(null != mRef){
            mRef = null;
        }
    }

    public static interface PageRemovedCallback{

        void pageRemoved();
    }

    public static interface PageSwitchedCallback{

        void PageSwitchedCallback();
    }

    private boolean isCallCycleNo() {

        //是否叫号白名单下开启客户周期
        boolean hasWhite = (Boolean) SharedPreferencesUtil.getInstance().get(ReflectionApplication.getApplication(), CALL_WHITE, false);
        if(hasWhite){

            String cycleNo = (String)SharedPreferencesUtil.getInstance().get(ReflectionApplication.getApplication(), CUSTOM_CYCLE_NO, "");

            if(TextUtils.isEmpty(cycleNo)){
                return false;
            }else {
                return true;
            }

        }else {
            return true;
        }

    }
    
    //设备是否绑定叫号机
    private boolean deviceIsBinding(){

        return (Boolean) SharedPreferencesUtil.getInstance().get(ReflectionApplication.getApplication(), IS_DEVICE_BINDING, false);
    }

    private boolean hasTTrans(){

        if(null==menuTips || menuTips.isEmpty()) return false;

        for(SwancsSystemTipsBean swancsSystemTip : menuTips){

            if(null!=swancsSystemTip && TextUtils.equals("T", swancsSystemTip.transType)) return true;
        }

        return false;

    }

    //判断关闭界面是否清空杭小宝数据，当前是辅助交易，并且有主交易的时候，不清
    public boolean canDeleteHxb(String url){

        if(TextUtils.isEmpty(url)) return true;

        SwancsSystemTipsBean swancsSystemTips = getMenuTipByUrl(url);

        if(null == swancsSystemTips) return true;
        
        if(!TextUtils.equals("T", swancsSystemTips.transType) && hasTTrans()){

            return false;
        }

        return true;
    }

    public void deleteCapture(){
      ThreadUtils.post(new Runnable() {
          @Override
          public void run() {
              File file = new File(FileUtils.getAppFileDir(getContext(),"capture"));
              FileUtils.deleteFile(file);
          }
      });
    }
}
